<?php
/**
 * Created by PhpStorm.
 * User: zhendong
 * Date: 2017/4/17
 * Time: 9:50
 */
namespace Backend\Model;
use Think\Model;

class CustomerModel extends Model
{
    public function __construct() {
        parent::__construct();
    }

    protected $_validate = [
        //array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间])
        array('name', 'require', '请填写公司名称！'),
        array('company_type', 'require', '请选择公司类型！', '', '', 3),
    ];

    protected function _before_insert(&$data) {
        $data['ctime']=time();
    }

    public function get_customer_info($where = [], $field = '', $limit = '') {
        if(!empty($where) && is_array($where)) {
            return $this->where($where)->field($field)->limit($limit)->order('id DESC')->select();
        } else {
            return $this->limit($limit)->order('id DESC')->select();
        }
    }
}